<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class ChestType extends Model
{
    use SoftDeletes;

    protected $table = 'chest_type';


    //获取电柜箱子类型信息
    public static function getSelectOptions()
    {
        $options = self::pluck('type_name', 'id');
        return $options;
    }

    public function chestType()
    {
        return $this->belongsTo(Chest::class, 'id');
    }


    public function setPackageIdAttribute($value)
    {
        $this->attributes['package_id'] = implode(',', $value);
    }


    public function getPackageIdAttribute($value)
    {
        if (strpos($value, ',')) {
            return explode(',', $value);
        }
        return [$value];
    }
   //查询套餐信息
    public function package()
    {
        return $this->belongsTo(Package::class, 'id');
    }

}
